//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;
using CommunityServer.Galleries.Controls;

namespace CommunityServer.ControlPanel.Photos
{
	/// <summary>
    /// Summary description for ModalQuickAdd.
	/// </summary>
    public class ModalQuickAdd : BaseGalleryPage
	{

		#region Child Controls

		protected MPContainer MPContainer;
        protected QuickAddPhoto QuickAddPhoto1;

		#endregion
		protected CommunityServer.ControlPanel.Controls.ResourceButton Cancel;

		protected int PostID;
		protected CommunityServer.Controls.ResourceControl ResourceControl1;
		protected CommunityServer.Controls.MPContent bcr;

		protected CSContext context = null;

		private void Page_Load(object sender, EventArgs e)
		{
		    int _sectionID = CSContext.Current.GetIntFromQueryString("sectionid",-1);
            if(_sectionID > 0)
                QuickAddPhoto1.SectionID = _sectionID;
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
        }
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Cancel.Click += new System.EventHandler(this.CancelButton_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		protected override void Authorize()
		{
			//make sure the user is authenticated
			base.Authorize ();
			
			//the user needs to be the gallery owner or moderator or above to edit a post
			Permissions.AccessCheck( this.CurrentGallery , Permission.Post, CSContext.Current.User );
		}

        public void CancelButton_Click(object sender, EventArgs e)
        {
            CSContext cnxt = CSContext.Current;
            if (cnxt.ReturnUrl != null && cnxt.ReturnUrl.Length > 0)
                cnxt.Context.Response.Redirect(cnxt.ReturnUrl);
            else
                cnxt.Context.Response.Redirect(Globals.AppendQuerystring(GalleryUrls.Instance().ControlPanel_Photos_PostList, String.Format("sectionid={0}", CurrentGallery.SectionID.ToString())));
        }

	}
}
